<template>
  <!-- 搜索歌单 -->
  <div class="sc-playlist">
    <search-not-found v-if="!found"></search-not-found>
    <div v-if="found">
      <ul class="pls-lists clearfix">
        <li class="pls-item" v-for="(item, index) in playlists" :key="index">
          <c-play-list :item="item"></c-play-list>
          <!-- <span style="width: 190px; height: 190px; margin-right: 20px"></span> -->
          <!-- <p>1231</p> -->
        </li>
      </ul>
      <div class="pls-el-pagination" v-if="playlistCount > 30">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="30"
          layout="prev, pager, next, jumper"
          :total="playlistCount"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import CPlayList from "components/classify/CPlayList.vue";
import SearchNotFound from "views/search/child/SearchNotFound";

export default {
  components: {
    CPlayList,
    SearchNotFound,
  },
  data() {
    return {
      playlists: [],
      currentPage: 1,
      playlistCount: 0,
      found: true,
    };
  },
  mounted() {
    this.getSearchPLaylist();
  },
  methods: {
    handleCurrentChange() {
      this.getSearchPLaylist();
      document.documentElement.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
    getSearchPLaylist() {
      this.axios({
        url:
          "/cloudsearch?type=1000&keywords=" +
          this.$store.state.MInput +
          "&offset=" +
          (this.currentPage - 1) * 30,
      })
        .then((res) => {
          if (!res.data.result || res.data.code == 400) {
            this.found = false;
          } else {
            this.playlists = res.data.result.playlists;
            this.playlistCount = res.data.result.playlistCount;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
.sc-playlist {
  margin-bottom: 50px;
  padding: 20px;
  overflow: hidden;
}
.sc-playlist .pls-lists {
  margin-right: -20px;
}
.sc-playlist .pls-item {
  width: 20%;
  float: left;
}
.sc-playlist .pls-el-pagination {
  position: relative;
  text-align: center;
  margin: 20px auto;
}
</style>